{extend name="../template/admin/head.html"}
{block name="title"}
评论管理_{__block__}
{/block}
{block name="content"}
<blockquote class="layui-elem-quote news_search">
  说明：回复，评论回复，删除评论。
</blockquote>
<div class="layui-form news_list">
  <table class="layui-table">
    <colgroup>
    <col width="2%">
    <col width="10%">
    <col width="5%">
    <col width="5%">
    <col width="10%">
  </colgroup>
  <thead>
    <tr>
      <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose" id="allChoose"> 全选</th>
      <th style="text-align:left;">评论内容</th>
      <th>评论者</th>
      <th>文章</th>
      <th>操作</th>
    </tr> 
  </thead>
  <tbody class="news_content">
    <colgroup>
    <col width="150">
    <col width="200">
    <col>
  </colgroup>
  <tbody>
    {volist name="list" id="list"}
    <tr id="data{$list.uid}">
      <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose" id="allChoose"><input type="hidden" id="acid{$list.uid}" value="{$list.id}"></th>
      <td id="text{$list.uid}"  style="overflow: hidden;max-width: 100px">{$list.text}</td>
      <td id="name{$list.uid}">{$list.name}({$list.ip})</td>
      <td id="title{$list.uid}">{$list.title}</td>
      <td>
        <div class="layui-btn-group">
          <button class="layui-btn" onclick="addcom({$list.uid})">回复</button>
          <button class="layui-btn" onclick="edit({$list.uid})">编辑</button>
          <button class="layui-btn {if condition="($list.status == 0)"}{else/}layui-btn-danger{/if}" title="点击修改状态" onclick="show({$list.uid})">{if condition="($list.status == 0)"}显示{else/}隐藏{/if}</button>
          <button class="layui-btn" onclick="del({$list.uid})">删除</button>
        </div>
      </td>
    </tr>
    {/volist}
  </tbody>
</table>

</tbody>
</div>
</div>

{/block}
{block name="jssrc"}
<script type="text/javascript">
  layui.use(['form', 'layedit', 'laydate'], function() {
    var form = layui.form,
    layer = layui.layer,
    layedit = layui.layedit,
    laydate = layui.laydate;
  });
//编辑框显示并传递值
function edit(num){
  var id = num;
  var odlcomment = $('#text'+num).html();
  var content= "<div style=\"margin-top:10px; padding-right:10px;\">";
  content+= "<label class=\"layui-form-label\">内容：</label>";
  content+= "<div class=\"layui-input-block\">";
  content+= "<textarea  placeholder='请输入内容' class='layui-textarea' id='newcomment'>"+odlcomment+"</textarea></div><br>";
  content+= "</div>";
  content+= "<button class=\"layui-btn kit-login-btn\" lay-submit=\"submit\" lay-filter=\"wrnav\" id=\"wrnav\" style=\" float: right;margin-right:10px;margin-top:5px;\">修改</button>";
  layer.open({
    title:'编辑评论',
    type: 1,
    area: ['400px', '220px'],
      shadeClose: true, //点击遮罩关闭
      content: content,

    });
    //编辑
    layui.use('form', function(){
      var form = layui.form;    
      form.on('submit(wrnav)', function(date) {
        var newcomment = $("#newcomment").val();
        if (newcomment != "") {
          $.ajax({
            type:"POST",
            url:"{:URL('Comments/edit')}",
            dataType:"json",
            data:{id:id,text:newcomment},
            beforeSend: function () {
            // 禁用按钮防止重复提交
            $("#wrnav").attr({"disabled":"disabled"});
            $("#wrnav").addClass("layui-btn-disabled");
            $("#wrnav").html("修改中...");
            layer.load(1);
          },
          error: function (XmlHttpRequest, textStatus, errorThrown) {
            if (XmlHttpRequest.responseText != "") {
              layer.msg('提交失败，请稍后尝试！');
              layer.closeAll('loading');
              $("#wrnav").removeClass("layui-btn-disabled");
              $("#wrnav").removeAttr("disabled");  
              $("#wrnav").html("修改");
            }
          },
          success:function(data){
            //1为修改成功
            //2为修改失败
            if (data.result == "1") {
              layer.msg(data.msg);
              layer.closeAll('loading');
              $("#wrnav").removeClass("layui-btn-disabled");
              $("#wrnav").removeAttr("disabled");  
              $("#wrnav").html("修改");
              setTimeout(function(){
                location.reload();
              },1000);
            }else if(data.result = "2"){
              layer.closeAll('loading');
              layer.msg(data.msg);
              $("#wrnav").removeClass("layui-btn-disabled");
              $("#wrnav").removeAttr("disabled");  
              $("#wrnav").html("修改");
            }
          }
        });
          return false;
        }else{
          layer.msg('所有内容不能为空!');
          return false;
        }
      });
    });

  }
//删除数据
function del(id){
  layer.confirm('确认删除？', {
  btn: ['确认','取消'] //按钮
}, function(){
  if (id != "") {
    $.ajax({
      type:"POST",
      url:"{:URL('Comments/delcom')}",
      dataType:"json",
      data:{id:id},
      beforeSend: function () {
            // 动画显示
            layer.load(1);
          },
          error: function (XmlHttpRequest, textStatus, errorThrown) {
            if (XmlHttpRequest.responseText != "") {
              layer.msg('提交失败，请稍后尝试！');
            }
          },
          success:function(data){
            //1为删除成功
            //2为删除失败
            if (data.result == "1") {
              layer.msg(data.msg);
              layer.closeAll('loading');
              $('#data'+id).remove();
            }else if(data.result = "2"){
              layer.closeAll('loading');
              layer.msg(data.msg);
            }
          }
        });
    return false;
  }else{
    layer.msg('ID值为空!');
    return false;
  }
});
}   
//回复
function addcom(id){
    com_id = id;
    ac_id  = $('#acid'+id).val();
  var content= "<div style=\"margin-top:10px; padding-right:10px;\">";
  content+= "<label class=\"layui-form-label\">内容：</label>";
  content+= "<div class=\"layui-input-block\">";
  content+= "<textarea  placeholder='请输入内容' class='layui-textarea' id='comment'></textarea></div><br>";
  content+= "</div>";
  content+= "<button class=\"layui-btn kit-login-btn\" lay-submit=\"submit\" lay-filter=\"tjcom\" id=\"tjcom\" style=\" float: right;margin-right:10px;margin-top:5px;\">回复</button>";
  layer.open({
    title:'回复评论',
    type: 1,
    area: ['400px', '220px'],
      shadeClose: true, //点击遮罩关闭
      content: content,

    });
    //编辑
    layui.use('form', function(){
      var form = layui.form;    
      form.on('submit(tjcom)', function(date) {
        text   = $('#comment').val();
        if (text != "") {
          $.ajax({
            type:"POST",
            url:"{:URL('Comments/addcom')}",
            dataType:"json",
            data:{com_id:com_id,text:text,ac_id:ac_id},
            beforeSend: function () {
            // 禁用按钮防止重复提交
            $("#tjcom").attr({"disabled":"disabled"});
            $("#tjcom").addClass("layui-btn-disabled");
            $("#tjcom").html("修改中...");
            layer.load(1);
          },
          error: function (XmlHttpRequest, textStatus, errorThrown) {
            if (XmlHttpRequest.responseText != "") {
              layer.msg('提交失败，请稍后尝试！');
              layer.closeAll('loading');
              $("#tjcom").removeClass("layui-btn-disabled");
              $("#tjcom").removeAttr("disabled");  
              $("#tjcom").html("修改");
            }
          },
          success:function(data){
            //1为修改成功
            //2为修改失败
            if (data.result == "1") {
              layer.msg(data.msg);
              layer.closeAll('loading');
              $("#tjcom").removeClass("layui-btn-disabled");
              $("#tjcom").removeAttr("disabled");  
              $("#tjcom").html("修改");
              setTimeout(function(){
                location.reload();
              },1000);
            }else if(data.result = "2"){
              layer.closeAll('loading');
              layer.msg(data.msg);
              $("#tjcom").removeClass("layui-btn-disabled");
              $("#tjcom").removeAttr("disabled");  
              $("#tjcom").html("修改");
            }
          }
        });
          return false;
        }else{
          layer.msg('所有内容不能为空!');
          return false;
        }
      });
    });

  }
//修改状态
function show(id){
  $.ajax({
    type:"POST",
    url:"{:URL('Comments/showstatus')}",
    dataType:"json",
    data:{id:id},
    beforeSend: function () {
            // 加载动画
            layer.load(1);
          },
          error: function (XmlHttpRequest, textStatus, errorThrown) {
            if (XmlHttpRequest.responseText != "") {
              layer.closeAll('loading');
              layer.msg('提交失败，请稍后尝试！');
            }
          },
          success:function(data){
            //1为添加成功
            //2为添加失败
            if (data.result == "1") {
              layer.msg(data.msg);
              layer.closeAll('loading');
              setTimeout(function(){
                location.reload();
              },1000);
            }else if(data.result = "2"){
              layer.closeAll('loading');
              layer.msg(data.msg);
            }
          }
        });
}
</script>
{/block}
{/block}